<%@page import="models.FeedType"%>
<%@page import="models.Genre"%>
<%@page import="models.Country"%>
<%@page import="helpers.CountryHelper"%>
<%@page import="models.Software"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>App free</title>
</head>
<body>

<%
    ArrayList<Software> softwares = (ArrayList<Software>) request.getAttribute("softwares");
	ArrayList<Country> countries  = (ArrayList<Country>) request.getAttribute("countries");
	ArrayList<FeedType> types = (ArrayList<FeedType>) request.getAttribute("types");
	ArrayList<String> limits = (ArrayList<String>) request.getAttribute("limits");
	ArrayList<Genre> genres = (ArrayList<Genre>) request.getAttribute("genres");
	String country = (String) request.getAttribute("country");
	String type = (String) request.getAttribute("type");
	String limit = (String) request.getAttribute("limit");
	String genre = (String) request.getAttribute("genre");
%>
    <div class="search">
        <form action="/home" method="get" name="search">
            <table>
                <tr>
                    <td>Country</td>
                    <td>Feed Type</td>
                    <td>Size</td>
                    <td>Genre</td>
                    <td></td>
                </tr>
                <tr>
                    <td>
	                    <select name="country">
	                    <% for (int i = 0; i < countries.size(); i++) { %>    
	                    	<option value="<%=countries.get(i).getIosCode2Digit().toLowerCase() %>" <%=(country.equalsIgnoreCase(countries.get(i).getIosCode2Digit().toLowerCase()))?"selected=\"selected\"":"" %>><%=countries.get(i).getName() %></option>
	                    <% } %>
	                    </select>
                    </td>
                    <td>
                    	<select name="type">
	                    <% for (int i = 0; i < types.size(); i++) { %>    
	                    	<option value="<%=types.get(i).getAlias() %>" <%=(type.equalsIgnoreCase(types.get(i).getAlias()))?"selected=\"selected\"":"" %>><%=types.get(i).getName()%></option>
	                    <% } %>
	                    </select>
                    </td>
                    <td>
                    	<select name="limit">
	                    <% for (int i = 0; i < limits.size(); i++) { %>
	                    	<option value="<%=limits.get(i) %>" <%=(limit.equalsIgnoreCase((String) limits.get(i)))?"selected=\"selected\"":"" %>><%=limits.get(i)%></option>
	                    <% } %>
	                    </select>
                    </td>
                    <td>
                    	<select name="genre">
	                    <% for (int i = 0; i < genres.size(); i++) { %>    
	                    	<option value="<%=genres.get(i).getId() %>" <%=genre.equalsIgnoreCase((String) genres.get(1).getId())?"selected=\"selected\"":"" %>><%=genres.get(i).getName()%></option>
	                    <% }%>
	                    </select>
                    </td>
                    <td>
                    	<button type="submit">Search</button>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <% for (int i = 0; i < softwares.size(); i++) { %>
    <div class="software">
        <table>
            <tr>
                <td rowspan="2"><a href="/info?id=<%=softwares.get(i).getTrackId()%>"><img src="<%=softwares.get(i).getArtworkUrl512() %>"></a></td>
                <td><a href="<%=softwares.get(i).getTrackViewUrl() %>"><%=i+1 %>: <%=softwares.get(i).getTrackName() %></a></td>
            </tr>
            <tr>
                <td><%=softwares.get(i).getDescription().getValue() %></td>
            </tr>
        </table>
    </div>
    <hr />
    <% } %>
</body>
</html>